window.addEventListener('load', function() {
	//验证码
	var btn = document.querySelector('.btn')
	var time = 10
	btn.onclick = function() {
		btn.disabled = true
		time--
		btn.innerHTML = '还剩' + time + '秒再次发送'
		var timer = setInterval(function() {
			if (time == 0) {
				clearInterval(timer)
				btn.disabled = false
				btn.innerHTML = '发送'
				time = 10
			} else {
				time--
				btn.innerHTML = '还剩' + time + '秒再次发送'
			}
		}, 1000)
	}


	//登录密码
	var psd = document.querySelector('.psd')
	var img = document.querySelector('img')
	var pass = document.querySelector('.pass')
	var flag = true
	img.onclick = function() {
		if (flag == true) {
			img.src = 'images/open.png'
			pass.type = 'text'
			flag = false
		} else {
			img.src = 'images/close.png'
			pass.type = 'password'
			flag = true
		}
	}


	//手机号
	var tel = document.querySelector('.tel')
	var tip = document.querySelector('.tip')
	var tipt = document.querySelector('.tipt')
	tel.onfocus = function() {
		if (tel.value == '请输入手机号码') {
			tel.value = ''

		}
		tel.style.color = '#333'
	}
	tel.onblur = function() {
		if (tel.value == '') {
			tel.value = '请输入手机号码'

		}
		tel.style.color = '#999'
	}
	
	//手机号验证	
	var re = /^1[3-9]\d{9}$/
	//密码验证
	var repass = /^[a-zA-Z0-9_-]{6,16}$/
	
	trigger(tel, tip, re)
	trigger(pass, tipt, repass)
	
	function trigger(ele, nextele, reg){
		ele.addEventListener('input', function(){
			if(reg.test(this.value)){
				nextele.firstElementChild.className = 'success'
				nextele.lastElementChild.innerHTML = `格式正确`
				nextele.lastElementChild.className ='succ_writ'
			}else{
				nextele.firstElementChild.className = 'mistake'
				nextele.lastElementChild.innerHTML = `格式不正确，请重新输入`
				nextele.lastElementChild.className ='mis_writ'
			}
		})
	}
	//验证密码
	var qpss = document.querySelector('.qpass')
	var tipsan = document.querySelector('.tipsan')
	qpss.addEventListener('input', function(){
		if(this.value === pass.value){
				tipsan.firstElementChild.className = 'success'
				tipsan.lastElementChild.innerHTML = `密码一致`
				tipsan.lastElementChild.className ='succ_writ'
			}else{
				tipsan.firstElementChild.className = 'mistake'
				tipsan.lastElementChild.innerHTML = `密码不一致，请重新输入`
				tipsan.lastElementChild.className ='mis_writ'
		}
	})
	
})
